In [1]:
import pandas as pd
In [2]:
df = pd.read_csv('result.csv')
df
Out[2]:
Order_ID Product Quantity Price Total Order_Date Address Month Hour Day_name
0 176558 USB-C Charging Cable 2 11.95 23.90 2019-04-19 08:46:00 917 1st St, Dallas, TX 75001 4 8 Friday
1 176559 Bose SoundSport Headphones 1 99.99 99.99 2019-04-07 22:30:00 682 Chestnut St, Boston, MA 02215 4 22 Sunday
2 176560 Google Phone 1 600.00 600.00 2019-04-12 14:38:00 669 Spruce St, Los Angeles, CA 90001 4 14 Friday
3 176560 Wired Headphones 1 11.99 11.99 2019-04-12 14:38:00 669 Spruce St, Los Angeles, CA 90001 4 14 Friday
4 176561 Wired Headphones 1 11.99 11.99 2019-04-30 09:27:00 333 8th St, Los Angeles, CA 90001 4 9 Tuesday
... ... ... ... ... ... ... ... ... ... ...
185945 259353 AAA Batteries (4-pack) 3 2.99 8.97 2019-09-17 20:56:00 840 Highland St, Los Angeles, CA 90001 9 20 Tuesday
185946 259354 iPhone 1 700.00 700.00 2019-09-01 16:00:00 216 Dogwood St, San Francisco, CA 94016 9 16 Sunday
185947 259355 iPhone 1 700.00 700.00 2019-09-23 07:39:00 220 12th St, San Francisco, CA 94016 9 7 Monday
185948 259356 34in Ultrawide Monitor 1 379.99 379.99 2019-09-19 17:30:00 511 Forest St, San Francisco, CA 94016 9 17 Thursday
185949 259357 USB-C Charging Cable 1 11.95 11.95 2019-09-30 00:18:00 250 Meadow St, San Francisco, CA 94016 9 0 Monday

185950 rows × 10 columns

In [5]:
'917 1st St, Dallas, TX 75001'.split(',')[1].strip()
Out[5]:
'Dallas'
In [8]:
'917 1st St, Dallas, TX 75001'.split(',')[2].split(' ')[1]
Out[8]:
'TX'
In [9]:
def get_city(address):
    city = address.split(',')[1].strip()
    state = address.split(',')[2].split(' ')[1]
    return f'{city}, {state}'


df['City'] = df.Address.apply(get_city)
In [12]:
df.City.unique().size
Out[12]:
10
In [14]:
result = df.groupby('City')[['Total']].sum()
result
Out[14]:
Total
City
Atlanta, GA 2.795499e+06
Austin, TX 1.819582e+06
Boston, MA 3.661642e+06
Dallas, TX 2.767975e+06
Los Angeles, CA 5.452571e+06
New York City, NY 4.664317e+06
Portland, ME 4.497583e+05
Portland, OR 1.870732e+06
San Francisco, CA 8.262204e+06
Seattle, WA 2.747755e+06
In [15]:
import matplotlib.pyplot as plt
In [19]:
plt.figure(figsize=(10, 6))
plt.bar(result.index, result.Total)
plt.gcf().axes[0].yaxis.get_major_formatter().set_scientific(False)

plt.xticks(result.index, rotation='vertical')
# plt.yticks(range(0, int(round(res.max()[0])), 500000))

plt.xlabel('Города')
plt.ylabel('Выручка, $')

for index, value in enumerate(result.Total):
    plt.text(
        index,
        500000,
        '{0:,}'.format(round(value)).replace(',', ' '),
        rotation='vertical',
        size='15',
        color='#000',
        ha='center')

plt.grid()
plt.show()
In [ ]: